import 'package:flutter/material.dart';
import 'package:flutter_axrjc/datasource/network/bean/AssetBean.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';

Future<List<AssetBean>> showSelectMediaDialog() async {
  ImagePicker imagePicker = ImagePicker();
  return await showModalBottomSheet(
      context: Get.context!,
      builder: (c) => SingleChildScrollView(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                children: [
                  const Padding(
                    padding: EdgeInsets.all(8.0),
                    child: Center(
                      child: Text("请选择"),
                    ),
                  ),
                  InkWell(
                    onTap: () async {
                      XFile? xf = await imagePicker.pickImage(
                          source: ImageSource.gallery);
                      if (xf != null) {
                        Get.back(result: [
                          AssetBean(
                              name: xf.name,
                              path: xf.path,
                              type: AssetType.video)
                        ]);
                      } else {
                        Get.back();
                      }
                    },
                    child: const Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Row(
                        children: [
                          Icon(
                            Icons.image_outlined,
                          ),
                          Padding(
                            padding: EdgeInsets.all(8.0),
                            child: Text("选择单图"),
                          ),
                        ],
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () async {
                      XFile? xf = await imagePicker.pickImage(
                          source: ImageSource.camera);
                      if (xf != null) {
                        Get.back(result: [
                          AssetBean(
                              name: xf.name,
                              path: xf.path,
                              type: AssetType.video)
                        ]);
                      } else {
                        Get.back();
                      }
                    },
                    child: const Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Row(
                        children: [
                          Icon(
                            Icons.linked_camera_outlined,
                          ),
                          Padding(
                            padding: EdgeInsets.all(8.0),
                            child: Text("拍摄单图"),
                          ),
                        ],
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () async {
                      List<XFile> xf = await imagePicker.pickMultiImage();
                      if (xf.isNotEmpty) {
                        Get.back(
                            result: xf
                                .map((e) => AssetBean(
                                    name: e.name,
                                    path: e.path,
                                    type: AssetType.image))
                                .toList());
                      } else {
                        Get.back(result: []);
                      }
                    },
                    child: const Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Row(
                        children: [
                          Icon(
                            Icons.photo_album_outlined,
                          ),
                          Padding(
                            padding: EdgeInsets.all(8.0),
                            child: Text("选择多图"),
                          ),
                        ],
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () async {
                      XFile? xf = await imagePicker.pickVideo(
                          source: ImageSource.gallery);
                      if (xf != null) {
                        Get.back(result: [
                          AssetBean(
                              name: xf.name,
                              path: xf.path,
                              type: AssetType.video)
                        ]);
                      } else {
                        Get.back();
                      }
                    },
                    child: const Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Row(
                        children: [
                          Icon(
                            Icons.video_collection_outlined,
                          ),
                          Padding(
                            padding: EdgeInsets.all(8.0),
                            child: Text("选择视频"),
                          ),
                        ],
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () async {
                      XFile? xf = await imagePicker.pickVideo(
                          source: ImageSource.camera);
                      if (xf != null) {
                        Get.back(result: [
                          AssetBean(
                              name: xf.name,
                              path: xf.path,
                              type: AssetType.video)
                        ]);
                      } else {
                        Get.back();
                      }
                    },
                    child: const Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Row(
                        children: [
                          Icon(
                            Icons.video_camera_back_outlined,
                          ),
                          Padding(
                            padding: EdgeInsets.all(8.0),
                            child: Text("拍摄视频"),
                          ),
                        ],
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      Get.back();
                    },
                    child: const Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Row(
                        children: [
                          Icon(
                            Icons.cancel_outlined,
                            color: Colors.red,
                          ),
                          Padding(
                            padding: EdgeInsets.all(8.0),
                            child: Text("取消"),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ));
}

Future<AssetBean?> showSingleMedia() async {
  ImagePicker imagePicker = ImagePicker();
  return await showModalBottomSheet(
      context: Get.context!,
      builder: (c) => SingleChildScrollView(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                children: [
                  const Padding(
                    padding: EdgeInsets.all(8.0),
                    child: Center(
                      child: Text("请选择"),
                    ),
                  ),
                  InkWell(
                    onTap: () async {
                      XFile? xf = await imagePicker.pickImage(
                          source: ImageSource.gallery);
                      if (xf != null) {
                        Get.back(
                            result: AssetBean(
                                name: xf.name,
                                path: xf.path,
                                type: AssetType.video));
                      } else {
                        Get.back();
                      }
                    },
                    child: const Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Row(
                        children: [
                          Icon(
                            Icons.image_outlined,
                          ),
                          Padding(
                            padding: EdgeInsets.all(8.0),
                            child: Text("选择图片"),
                          ),
                        ],
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () async {
                      XFile? xf = await imagePicker.pickVideo(
                          source: ImageSource.gallery);
                      if (xf != null) {
                        Get.back(
                            result: AssetBean(
                                name: xf.name,
                                path: xf.path,
                                type: AssetType.video));
                      } else {
                        Get.back();
                      }
                    },
                    child: const Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Row(
                        children: [
                          Icon(
                            Icons.video_collection_outlined,
                          ),
                          Padding(
                            padding: EdgeInsets.all(8.0),
                            child: Text("选择视频"),
                          ),
                        ],
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      Get.back();
                    },
                    child: const Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Row(
                        children: [
                          Icon(
                            Icons.cancel_outlined,
                            color: Colors.red,
                          ),
                          Padding(
                            padding: EdgeInsets.all(8.0),
                            child: Text("取消"),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ));
}
